﻿@model BudgetMealsModels.Entities.Recipe
@{
    ViewBag.Title = Model.Name;
}
@*@{ Html.RenderPartial("TinyMCE", new string[] { "#ReviewBox", ".ReplyBox" }); }*@
<div style="float: left; width: 400;">
@if(Model.ImageGallery != null){
    <div id="ImageGallery" style="text-align: center; width: 100%;">
        @for(int i = 0; i < Model.ImageGallery.Count; i++)
        {
            <a class="thumbnail" href="#thumb"><img height="125" width="125" src="@Url.Action("GetImage", "Recipe", new { recipeId = Model.RecipeID, image = i })" alt="thumbnailImage" /><span><img src="@Url.Action("GetImage", "Recipe", new { recipeId = Model.RecipeID, image = i })" width="300px" alt="EnlargedImage"/></span></a>
        }
    </div>
}
    <h2 id="recipeTitle">@Model.Name by @Html.ActionLink(@Model.UserCreated, "Profile", "User", new { id = Model.UserCreatedID }, null)</h2>
        <div id="starRating">
            @{ Html.RenderPartial("Rating", Model.Rating); }
        </div>
    <h4>Total Cost:<span>$@Model.Cost.ToString("N2") per serving</span></h4>        
    <h3 style="height:30px">Ingredients</h3>
    @if (Model.Ingredients != null && Model.Ingredients.Count() > 0)
    {
        <table style="margin-left: 25px; width: 800px;">
        @for (int i = 0; i < Model.Ingredients.Count(); i += 2)
        {
            <tr>
                <td style="height:25px">@Model.Ingredients[i].Measurement @Model.Ingredients[i].Name ($@Model.Ingredients[i].Cost.ToString("N2"))</td>
                @if (i + 1 < Model.Ingredients.Count())
                {
                    <td>@Model.Ingredients[i + 1].Measurement @Model.Ingredients[i + 1].Name ($@Model.Ingredients[i + 1].Cost.ToString("N2"))</td>
                }
            </tr>
        }
        </table>
    }
    else
    {
        <p style="margin-left: 25px;">No ingredients needed.</p>
    }
    <h3 style="margin-top:15px">
        Instructions</h3>
    @if (Model.Instructions != null)
    {
        <p style="margin-left: 25px;">@Html.Raw(Model.Instructions)</p>
    }
    else
    {
        <p style="margin-left: 25px;">No instructions needed.</p>
    }
</div>
<div style="float: right; width: 200px">
    @{ Html.RenderAction("Related", "Recipe", new { RecipeID = Model.RecipeID }); }
</div>
<script type="text/javascript">
    var AddReplyURL = "@Url.Action("AddReply", "Comment", new { parentID = "ParentIDValue", Review = "ReviewValue" })".replace("&amp;", "&");
    function AddReply(CommentID) {
        $.ajax(
            {
                url: AddReplyURL.replace("ParentIDValue", CommentID).replace("ReviewValue", $("#Comment" + CommentID).val()),
                type: "POST",
                success: function(response)
                {
                    $("#Replies" + CommentID).append(response);
                }
            }
        )
        $("#Comment" + CommentID).val("");
    }

    var AddReviewURL = "@Url.Action("AddReview", "Comment", new { recipeID = "RecipeIDValue", Rating = "RecipeRatingValue", Review = "ReviewValue" })".replace("&amp;", "&");
    function AddReview(recipeId) {
        $.ajax(
            {
                url: AddReviewURL.replace("RecipeIDValue", recipeId).replace("ReviewValue", $("#ReviewBox").val()).replace("RecipeRatingValue", $("#RecipeRating").val()).replace("&amp;", "&"),
                type: "POST",
                success: function(response)
                {
                    $("#Reviews").append(response);
                }
            }
        )
        $("#ReviewBox").val("");
        $("#RecipeRating").val("");
    }

    var DeleteReplyURL = "@Url.Action("Delete", "Comment", new { id = "IDValue" })".replace("&amp;","&")
    function DeleteReply(CommentID){
        $.ajax(
            {
                url: DeleteReplyURL.replace("IDValue", CommentID),
                type: "POST",
                success: function()
                {
                    $("#Reply" + CommentID).remove();
                }
            }
        )
    }

    var DeleteReviewURL = "@Url.Action("Delete", "Comment", new { id = "IDValue" })".replace("&amp;", "&")
    function DeleteReview(CommentID){
        $.ajax(
            {
                url: DeleteReviewURL.replace("IDValue", CommentID),
                type: "POST",
                success: function()
                {
                    $("#Review" + CommentID).remove();
                }
            }
        )
    }
</script>
<div class="ClearFix"></div>
<hr style="color: #FFFFFF; margin: 25px 0px;"/>
@if (Session["CurrentUser"] != null)
{
    Html.RenderPartial("../Comment/ShowComments", Model);
}
else
{
    @:You must @Html.ActionLink("Sign in", "Login", "Home", new { url = Request.Url.PathAndQuery }, null) <span>or</span> @Html.ActionLink("Register", "Create", "User") to view and post comments.
}
